let db = openDatabase('localmsg', '1.0', 'Test DB', 2 * 1024 * 1024)

export function run (sql, param = []) {
  return new Promise((resolve, reject) => {
    db.transaction(function (tx) {
      tx.executeSql(sql, param, function (tx, results) {
        let isGet = /^\s*select\s+/i.test(sql)
        if (isGet) {
          return resolve(Array.from(results.rows))
        } else {
          resolve(results)
        }
      }, function (tx, err) {
        reject(err.message)
      })
    })
  })
}
